package com.iplant.pdm.controller.fpc;

import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.pdm.service.FPCService;
import com.iplant.pdm.service.FRMService;
import com.iplant.pdm.service.po.bop.FPCRouteBPM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 工艺路线审批控制器
 *
 * @author YouWang·Peng
 * 2023-9-27 15:06:47
 */
@RestController
@RequestMapping("/api/FPCRouteBPM")
public class FPCRouteBPMController extends BasicController<FPCRouteBPM> {
    private static final Logger logger = LoggerFactory.getLogger(FPCRouteBPMController.class);

    @Autowired
    FRMService mFRMService;

    public FPCRouteBPMController() {
        super(FPCRouteBPM.class);
    }

    /**
     * 查询任务（网页版）
     */
    @GetMapping("/EmployeeAllWeb")
    public Object EmployeeAllWeb(HttpServletRequest request) {
        Object wResult = new Object();
        try {
            BMSEmployee wLoginUser = GetSession(request);

            Map<String, Object> wParams = GetParamsMap(request);

            if (!wParams.containsKey("Status")) {
                return GetResult(RetCode.SERVER_CODE_ERR, RetCode.SERVER_RST_ERROR_OUT);
            }

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<FPCRouteBPM>> wServiceResult =
                    mFRMService.BPM_QueryEmployeeAllWeb(wLoginUser, wParams, wPagination);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }
}
